package com.zx.controller.pageSkip.user;

import com.zx.model.user.User;
import com.zx.util.MallConstant;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author sunkai
 * @date 2022/8/25 0025 21:30
 * @mood zhou xun
 */
@Controller
public class UserSkip {

    @RequestMapping("/user/skip/index/{id}")
    public String gotoIndex(Model model, @PathVariable Long id){
        model.addAttribute("userId",id);
        return "index";
    }
    @RequestMapping("/user/skip/login")
    public String login(){
        return "login";
    }
    @RequestMapping("/")
    public String index(Model model, @CookieValue(value = "UserToken") String userToken){
        User user = MallConstant.MAP.get(userToken);
        if (user==null){
            return "login";
        }
        model.addAttribute("userId",user.getId());
        return "index";
    }
}
